// 统一封装接口方法
// 每个方法负责请求一个url
import axios from '@/utils/request'
import { getStorage } from '@/utils/storage'
// 引出模块合集
export * from './ArticleDetail.js'

// 登录接口
export const loginAPI = ({ mobile, code }) =>
  axios({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })

// 用户-刷新token
export const getNewTokenAPI = () =>
  axios({
    url: '/v1_0/authorizations',
    method: 'PUT',
    headers: {
      Authorization: 'Bearer ' + getStorage('refresh_token')
    }
  })

// 用户-获取个人资料
export const userProfileAPI = () =>
  axios({
    url: '/v1_0/user/profile'
  })

// 用户 - 基本资料
export const userInfoAPI = () =>
  axios({
    url: '/v1_0/user'
  })
// 用户 - 更新资料
export const updateUserInfoAPI = (obj) => {
  axios({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data: obj
    //  {
    //   name, // 昵称
    //   gender, // 性别0：男,1：女
    //   birthday, // 生日(要求格式：年-月-日 字符串)
    //   intro// 个人介绍
    // }
  })
}
// 用户- 更新头像
export const updatePhotoAPI = (formObj) =>
  axios({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: formObj
    // 如果你的请求体内容是表单对象, 浏览器会自动携带请求头Content-Type为multipart/form-data
  })

// 频道获取所有
export const getAllchannelsAPI = () =>
  axios({
    url: '/v1_0/channels'
  })

// 用户选择的频道
// 注意:用户没有登录，默认返回后台设置的默认频道列表
export const getUserchannelsAPI = () =>
  axios({
    url: '/v1_0/user/channels'
    // headers: { Authorization: `Bearer ${getToken()}` }
  })

// 更新覆盖频道
export const updateChannelAPI = ({ channels }) =>
  axios({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels // 用户已选整个频道数组
    }
  })

// 删除用户指定的频道
export const removeThenChannelAPI = ({ channelId }) =>
  axios({
    url: `/v1_0/user/channels/${channelId}`,
    method: 'DELETE'
  })

// 获取文章列表
export const getAllArticleListAPI = ({ channel_id, timestamp }) =>
  axios({
    url: '/v1_0/articles',
    params: {
      channel_id,
      timestamp
    }
  })

// 反馈不感兴趣
export const dislikeArticleAPI = (artId) =>
  axios({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    // headers: { Authorization: `Bearer ${getToken()}` },
    data: {
      target: artId
    }
  })

// 反馈-举报文章
export const articleReportsAPI = ({ artId, typeId }) =>
  axios({
    url: '/v1_0/article/reports',
    method: 'POST',
    // headers: { Authorization: `Bearer ${getToken()}` },
    data: {
      target: artId,
      type: typeId
    }
  })

// 搜索 - 联想菜单
export const suggestListAPI = ({ keywords }) =>
  axios({
    url: '/v1_0/suggestion',
    params: {
      q: keywords
    }
  })

// 搜索结果列表
export const serachResultAPI = ({ page = 1, per_page = 10, q }) =>
  axios({
    url: '/v1_0/search',
    params: {
      page,
      per_page,
      q
    }
  })
